package com.example.jinyongjie.test_opengles.objects;

import com.example.jinyongjie.test_opengles.util.VertexArray;
import com.example.jinyongjie.test_opengles.programs.TextureShaderProgram;
import com.example.jinyongjie.test_opengles.util.Constants;

import static android.opengl.GLES20.GL_TRIANGLES;
import static android.opengl.GLES20.glDrawArrays;

/**
 * Created by jinyongjie on 17/3/23.
 */
public class Table {
    private static  final  int POSITION_COMPONENT_COUNT = 2;
    private static final int TEXTURE_COORDINATES_COMPONENT_COUNT = 2;

    private static final int STRIDE  = (POSITION_COMPONENT_COUNT + TEXTURE_COORDINATES_COMPONENT_COUNT)* Constants.BYTES_PER_FLOAT;

    private static final float[] VERTEX_DATA = {
            -0.5f,-0.8f,0f,1f,
            0.5f,0.8f,1f,0f,
            -0.5f,0.8f,0f,0f,

            -0.5f,-0.8f,0f,1f,
            0.5f,-0.8f,1f,1f,
            0.5f,0.8f,1f,0f,
    };
    private VertexArray m_vertexArray;
    public Table()
    {
        m_vertexArray = new VertexArray(VERTEX_DATA);
    }
    public void bindData(TextureShaderProgram program)
    {
        m_vertexArray.setVertexAttribPointer(0,
                program.getPositionAttributeLocation(),
                POSITION_COMPONENT_COUNT,
                STRIDE);
        m_vertexArray.setVertexAttribPointer(POSITION_COMPONENT_COUNT,
                program.getTextureCoordinatesAttributeLocation(),
                TEXTURE_COORDINATES_COMPONENT_COUNT,
                STRIDE);
    }

    public void draw()
    {
        glDrawArrays(GL_TRIANGLES, 0, 6);
    }
}
